//
//  Untitled.swift
//  Pods
//
//  Created by ymac on 2024/11/7.
//

internal class tnBYYFXCziGIIYJa: NSObject {
    static let CJetjtaxiEfFwShK = UUdRjWYGnADOehEe()
    
    static func XkrEwFxlejMKimsy(jkid: xyFCtuUTCjzrfNrZ, jkparam: [String : Any?], callback: @escaping (_ isSuccess: Bool, _ results: [NSDictionary]?) -> Void) {
        do {
            if cQvWbqepOvFiLmsn.yYHjAmhheGFNDIUq == nil || cQvWbqepOvFiLmsn.yYHjAmhheGFNDIUq!.appKey == nil { return }
            let CurTime = Int(Date().timeIntervalSince1970 * 1000)
            let Nonce = "\(CurTime)_\(Int.random(in: 0...2147483647))"
            var request = URLRequest(url: URL(string: "\(aVvEJGjTiLCfWcNk.NyEuJqWOupFxfmWI)/sdk/api")!)
            request.httpMethod = "POST"
            request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
            request.setValue(cQvWbqepOvFiLmsn.yYHjAmhheGFNDIUq!.appKey!, forHTTPHeaderField: "sign-appkey")
            request.setValue(Nonce, forHTTPHeaderField: "sign-nonce")
            request.setValue("\(CurTime)", forHTTPHeaderField: "sign-curTime")
            request.setValue(xtbdoqUXkBQGJAkB.lSVkTwalLJbjGSHv(content: "\(cQvWbqepOvFiLmsn.yYHjAmhheGFNDIUq!.appKey!)\(Nonce)\(CurTime)"), forHTTPHeaderField: "sign-checkSum")
            request.httpBody = "jkid=\(jkid.rawValue)&jkparam=\(String(data: try JSONSerialization.data(withJSONObject: jkparam), encoding: .utf8)!)".data(using: .utf8)
            let session = URLSession(configuration: .default, delegate: CJetjtaxiEfFwShK, delegateQueue: .main)
            session.dataTask(with: request) { data, response, error in
                if error != nil || data == nil {
                    callback(false, nil)
                    return
                }
                do {
                    let body = ((try JSONSerialization.jsonObject(with: data!)) as! NSDictionary)["root"] as! NSDictionary
                    if body["code"] as? String != "200" {
                        callback(false, nil)
                        return
                    }
                    callback(true, (body["result"] as! [NSDictionary]))
                } catch {
                    callback(false, nil)
                }
            }.resume()
        } catch {
            callback(false, nil)
        }
    }
}

internal class UUdRjWYGnADOehEe: NSObject, URLSessionDelegate {
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
            completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
        }
    }
}
